/*package net.mysoft.budgetsoft.system.service.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import net.mysoft.budgetsoft.system.dao.FlowTaskNodeDao;
import net.mysoft.budgetsoft.system.dao.impl.FlowDaoImpl;
import net.mysoft.budgetsoft.system.domain.TFlowTaskNode;
import net.mysoft.budgetsoft.system.domain.TYongHu;
import net.mysoft.budgetsoft.system.pagemodel.DictionaryDetail;
import net.mysoft.budgetsoft.system.pagemodel.FlowTaskNode;
import net.mysoft.budgetsoft.system.service.FlowTaskNodeService;
import net.mysoft.framework.model.DataGrid;
import net.mysoft.framework.model.SessionInfo;
import net.mysoft.framework.util.ResourceUtil;
import net.mysoft.framework.util.UrlUtil;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.hibernate.ObjectNotFoundException;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

*//**
 * 
 * @author dagongPGP v1.0
 * @link <a href=http://www.dagongsoft.net>北京大公信软科技有限公司</a>
 * 
 * @version $Revision: 1.00 $Date: 2013-07-08 17:26:33
 *//*
@Service("flowTaskNodeService")
public class FlowTaskNodeServiceImpl implements FlowTaskNodeService {
	private static final Logger logger = Logger.getLogger(FlowDaoImpl.class);
	@Resource
	private FlowTaskNodeDao flowTaskNodeDao;
	@Resource
	private XiangMuJBXXService xiangMuJBXXService;

	public FlowTaskNodeDao getFlowTaskNodeDao() {
		return this.flowTaskNodeDao;
	}

	public void setFlowTaskNodeDao(FlowTaskNodeDao flowTaskNodeDao) {
		this.flowTaskNodeDao = flowTaskNodeDao;
	}

	@Override
	public List<FlowTaskNode> findAll(FlowTaskNode flowTaskNode) {
		//System.out.println("flowTaskNode.getXiangMuJBXXBH()" + flowTaskNode.getXiangMuJBXXBH());
		String hql = "from TFlowTaskNode tFlowTaskNode where 1=1 ";
		List params = new ArrayList();
		hql = addWhere(flowTaskNode, hql, params, null, null, null, null);
		hql = addOrder(flowTaskNode, hql);
		List<TFlowTaskNode> toList = new ArrayList();
		if (flowTaskNode.getPage() == 0 && flowTaskNode.getRows() == 0) {
			toList = flowTaskNodeDao.find(hql, params);
		} else {
			toList = flowTaskNodeDao.find(hql, params, flowTaskNode.getPage(), flowTaskNode.getRows());
		}
		List<FlowTaskNode> oList = new ArrayList<FlowTaskNode>();
		oList = changeModel(toList);
		return oList;
	}

	public FlowTaskNode get(String ftn_ID) {
		Object o = flowTaskNodeDao.get(TFlowTaskNode.class, ftn_ID);
		if (o != null) {
			return changeModel((TFlowTaskNode) o);
		}
		return null;
	}

	@Override
	public List<FlowTaskNode> find(FlowTaskNode flowTaskNode) {
		String hql = "from TFlowTaskNode tFlowTaskNode where 1=1 ";
		List params = new ArrayList();
		hql = addWhere(flowTaskNode, hql, params, null, null, null, null);
		hql = addOrder(flowTaskNode, hql);
		List<TFlowTaskNode> toList = new ArrayList();
		if (flowTaskNode.getPage() == 0 && flowTaskNode.getRows() == 0) {
			toList = flowTaskNodeDao.find(hql, params);
		} else {
			toList = flowTaskNodeDao.find(hql, params, flowTaskNode.getPage(), flowTaskNode.getRows());
		}
		List<FlowTaskNode> oList = new ArrayList<FlowTaskNode>();
		oList = changeModel(toList);

		// System.out.println(hql + "  已办工作");
		return oList;
	}

	@Override
	public List<FlowTaskNode> find_His(FlowTaskNode flowTaskNode) {

		String hql = "from TFlowTaskNode_His tFlowTaskNode where 1=1 and tFlowTaskNode.ftn_Status =2 ";
		List params = new ArrayList();

		hql = addWhere_His(flowTaskNode, hql, params, null, null, null, null);
		hql = addOrder(flowTaskNode, hql);
		List<TFlowTaskNode_His> toList = new ArrayList();
		if (flowTaskNode.getPage() == 0 && flowTaskNode.getRows() == 0) {
			toList = flowTaskNodeDao.find(hql, params);
		} else {
			toList = flowTaskNodeDao.find(hql, params, flowTaskNode.getPage(), flowTaskNode.getRows());
		}
		List<FlowTaskNode> oList = new ArrayList<FlowTaskNode>();
		oList = changeModel_His(toList);
		return oList;

		return null;
	}

	@Override
	public List<FlowTaskNode> find(FlowTaskNode flowTaskNode, String renWuHQL, List renWuHQLParams, String xiangMuHQL, List xiangMuHQLParams) {
		String hql = "from TFlowTaskNode tFlowTaskNode where 1=1 ";
		List params = new ArrayList();
		hql = addWhere(flowTaskNode, hql, params, renWuHQL, renWuHQLParams, xiangMuHQL, xiangMuHQLParams);
		hql = addOrder(flowTaskNode, hql);
		List<TFlowTaskNode> toList = flowTaskNodeDao.find(hql, params);
		List<FlowTaskNode> oList = new ArrayList<FlowTaskNode>();
		oList = changeModel(toList);
		return oList;
	}

	@Override
	public DataGrid datagrid_His(FlowTaskNode flowTaskNode, String renWuHQL, List renWuHQLParams, String xiangMuHQL, List xiangMuHQLParams) {
		
		 * DataGrid dg = new DataGrid(); String hql = "from TFlowTaskNode_His tFlowTaskNode where 1=1 and tFlowTaskNode.ftn_Status =2 "; List params = new ArrayList(); hql = addWhere_His(flowTaskNode, hql, params,renWuHQL,renWuHQLParams,xiangMuHQL,xiangMuHQLParams); String totalHql = "select count(*) " + hql; hql = addOrder(flowTaskNode, hql); List<TFlowTaskNode_His> toList = flowTaskNodeDao.find(hql, params, flowTaskNode.getPage(), flowTaskNode.getRows()); List<FlowTaskNode> oList = new ArrayList<FlowTaskNode>(); oList = changeModel_His(toList); dg.setTotal(flowTaskNodeDao.count(totalHql, params)); dg.setRows(oList); System.out.println(hql+"       更多已办工作"); return dg;
		 
		return null;
	}

	@Override
	public DataGrid datagrid(FlowTaskNode flowTaskNode, String renWuHQL, List renWuHQLParams, String xiangMuHQL, List xiangMuHQLParams) {
		DataGrid dg = new DataGrid();
		String hql = "from TFlowTaskNode tFlowTaskNode where 1=1 ";
		List params = new ArrayList();
		hql = addWhere(flowTaskNode, hql, params, renWuHQL, renWuHQLParams, xiangMuHQL, xiangMuHQLParams);
		String totalHql = "select count(*) " + hql;
		hql = addOrder(flowTaskNode, hql);
		List<TFlowTaskNode> toList = flowTaskNodeDao.find(hql, params, flowTaskNode.getPage(), flowTaskNode.getRows());
		List<FlowTaskNode> oList = new ArrayList<FlowTaskNode>();
		oList = changeModel(toList);
		dg.setTotal(flowTaskNodeDao.count(totalHql, params));
		dg.setRows(oList);
		
		return dg;
	}

	private String addWhere_His(FlowTaskNode flowTaskNode, String hql, List<Object> params, String renWuHQL, List renWuHQLParams, String xiangMuHQL, List xiangMuHQLParams) {
		// hql += " and tFlowTaskNode.xiangMuYCLX not like '%5-%' ";
		if (flowTaskNode.getXiangMuJBXXBH() != null && !"".equals(flowTaskNode.getXiangMuJBXXBH()) && !"null".equals(flowTaskNode.getXiangMuJBXXBH())) {
			hql += " and tFlowTaskNode.xiangMuJBXXBH = ?";
			params.add(flowTaskNode.getXiangMuJBXXBH());
		}
		if (flowTaskNode.getRenWuJBXXBH() != null && !"".equals(flowTaskNode.getRenWuJBXXBH()) && !"null".equals(flowTaskNode.getRenWuJBXXBH())) {
			hql += " and tFlowTaskNode.renWuJBXXBH = ?";
			params.add(flowTaskNode.getRenWuJBXXBH());
		}
		if (flowTaskNode.getFtn_Status() != null) {
			hql += " and tFlowTaskNode.ftn_Status = ?";
			params.add(flowTaskNode.getFtn_Status());
		}
		if (flowTaskNode.getFtn_HandleUserCode() != null) {
			SessionInfo sessionInfo = (SessionInfo) ServletActionContext.getRequest().getSession().getAttribute(ResourceUtil.getSessionInfoName());
			if (sessionInfo.getRoleIds().indexOf(ResourceUtil.ADMIN_ROLE_ID) < 0) {
				hql += " and tFlowTaskNode.ftn_HandleUserCode = ?";
				params.add(flowTaskNode.getFtn_HandleUserCode());
			}
		}
		if (flowTaskNode.getFtn_Class() != null) {
			if (flowTaskNode.getFtn_Class().indexOf(",") > 0) {
				String[] classArr = flowTaskNode.getFtn_Class().split(",");
				hql += " and tFlowTaskNode.flowNodeClass.fnc_ID in(";
				int x = 0;
				for (String cla : classArr) {
					if (x > 0) {
						hql += ",";
					}
					hql += "?";
					params.add(cla);
					x++;
				}
				hql += ")";
			} else {
				hql += " and tFlowTaskNode.flowNodeClass.fnc_ID = ?";
				params.add(flowTaskNode.getFtn_Class());
			}
		}
		if (flowTaskNode.getDatetimeEnd() != null && !flowTaskNode.getDatetimeEnd().equals("")) {

			hql += " and tFlowTaskNode.ftn_HandleBeginTime <= ? ";

			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String dateStr = sdf.format(flowTaskNode.getDatetimeEnd()) + " 23:59";
			try {
				params.add(new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(dateStr));
			} catch (ParseException e) {
				e.printStackTrace();
			}

		}
		if (flowTaskNode.getDatetimeStart() != null && !flowTaskNode.getDatetimeStart().equals("")) {
			hql += " and tFlowTaskNode.ftn_HandleBeginTime >= ? ";
			params.add(flowTaskNode.getDatetimeStart());
		}
		if (flowTaskNode.getEnddatetimeEnd() != null && !flowTaskNode.getEnddatetimeEnd().equals("")) {
			hql += " and tFlowTaskNode.ftn_HandleEndTime <= ? ";
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String dateStr = sdf.format(flowTaskNode.getEnddatetimeEnd()) + " 23:59";
			try {
				params.add(new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(dateStr));
			} catch (ParseException e) {
				e.printStackTrace();
			}

		}
		if (flowTaskNode.getEnddatetimeStart() != null && !flowTaskNode.getEnddatetimeStart().equals("")) {
			hql += " and tFlowTaskNode.ftn_HandleEndTime >= ? ";
			params.add(flowTaskNode.getEnddatetimeStart());
		}

		if (flowTaskNode.getYeWuZLBH() != null && !"".equals(flowTaskNode.getYeWuZLBH())) {
			hql += "and (tFlowTaskNode.renWuJBXXBH in(select tr.bianHao from TRenWuJBXX tr where tr.yeWuZL.bianHao=?) " + "or tFlowTaskNode.xiangMuJBXXBH in(select tx.xiangMuBH from TXiangMuJBXX tx where tx.yeWuZLWH.bianHao=?) ) ";
			params.add(flowTaskNode.getYeWuZLBH());
			params.add(flowTaskNode.getYeWuZLBH());
		}
		if (flowTaskNode.getQiYeMC() != null && !"".equals(flowTaskNode.getQiYeMC())) {
			hql += "and (tFlowTaskNode.renWuJBXXBH in(select tr.bianHao from TRenWuJBXX tr where tr.qiYeMC like ?) " + "or tFlowTaskNode.xiangMuJBXXBH in(select tx.xiangMuBH from TXiangMuJBXX tx where tx.shouPingZT.qiYeZWMC like ? or tx.shouPingZT.qiYeYWMC like ?) ) ";
			params.add("%" + flowTaskNode.getQiYeMC() + "%");
			params.add("%" + flowTaskNode.getQiYeMC() + "%");
			params.add("%" + flowTaskNode.getQiYeMC() + "%");
		}
		if (renWuHQL != null && !"".equals(renWuHQL)) {
			hql += " and tFlowTaskNode.renWuJBXXBH in(" + renWuHQL + ")";
			if (renWuHQLParams != null && renWuHQLParams.size() != 0) {
				params.addAll(renWuHQLParams);
			}
		}
		if (xiangMuHQL != null && !"".equals(xiangMuHQL)) {
			hql += " and tFlowTaskNode.xiangMuJBXXBH in(" + xiangMuHQL + ")";
			if (xiangMuHQLParams != null && xiangMuHQLParams.size() != 0) {
				params.addAll(xiangMuHQLParams);
			}
		}
		if (flowTaskNode.getXiangMuMC() != null & !"".equals(flowTaskNode.getXiangMuMC())) {
			hql += " and tFlowTaskNode.xiangMuJBXXBH in (select tt.xiangMuBH from TXiangMuJBXX tt where tt.xiangMuMC like ?) ";
			params.add("%" + flowTaskNode.getXiangMuMC() + "%");
		}
		if (flowTaskNode.getDatagridType() != null && flowTaskNode.getDatagridType().equals("xiangMuLCJK")) {
			hql += "  and tFlowTaskNode.ftn_ID in (select max(tt.ftn_ID) from TFlowTaskNode tt where tt.ftn_Status=1 group by tt.flow.flo_ID,tt.flowTemplateNode.ftn_ID) ";
		}
		if (flowTaskNode.getLiuChengJD() != null && !"".equals(flowTaskNode.getLiuChengJD()) && !"310".equals(flowTaskNode.getLiuChengJD())) {
			hql += " and tFlowTaskNode.ftn_Name_cn = ? ";
			params.add(flowTaskNode.getLiuChengJD());
		}
		if (flowTaskNode.getFtn_XiangMuJD() != null && flowTaskNode.getFtn_XiangMuJD() != 310) {
			hql += " and tFlowTaskNode.ftn_XiangMuJD = ? ";
			params.add(flowTaskNode.getFtn_XiangMuJD());
		}
		if (flowTaskNode.getFtn_State() != null && !"".equals(flowTaskNode.getFtn_State())) {
			hql += " and tFlowTaskNode.ftn_State = ? ";
			params.add(flowTaskNode.getFtn_State());
		}
		if (flowTaskNode.getXiangMuYCLX() != null && !"".equals(flowTaskNode.getXiangMuYCLX())) {
			hql += " and tFlowTaskNode.xiangMuYCLX like ?";
			params.add("%" + flowTaskNode.getXiangMuYCLX() + "%");
		}
		if (flowTaskNode.getFtn_Name_cn() != null && !"".equals(flowTaskNode.getFtn_Name_cn())) {
			hql += " and tFlowTaskNode.ftn_Name_cn=? ";
			params.add(flowTaskNode.getFtn_Name_cn());
		}
		if (flowTaskNode.getXiangMuZT() != null) {
			hql += " and (tFlowTaskNode.xiangMuJBXXBH is null or tFlowTaskNode.xiangMuJBXXBH in(select tx.xiangMuBH from TXiangMuJBXX tx where tx.xiangMuZT=?)) ";
			params.add(flowTaskNode.getXiangMuZT());
		}
		return hql;
	}

	private String addWhere(FlowTaskNode flowTaskNode, String hql, List<Object> params, String renWuHQL, List renWuHQLParams, String xiangMuHQL, List xiangMuHQLParams) {
		// hql += " and tFlowTaskNode.xiangMuYCLX not like '%5-%' ";
		if (flowTaskNode.getXiangMuJBXXBH() != null && !"".equals(flowTaskNode.getXiangMuJBXXBH()) && !"null".equals(flowTaskNode.getXiangMuJBXXBH())) {
			hql += " and tFlowTaskNode.xiangMuJBXXBH = ?";
			params.add(flowTaskNode.getXiangMuJBXXBH());
		}
		if (flowTaskNode.getRenWuJBXXBH() != null && !"".equals(flowTaskNode.getRenWuJBXXBH()) && !"null".equals(flowTaskNode.getRenWuJBXXBH())) {
			hql += " and tFlowTaskNode.renWuJBXXBH = ?";
			params.add(flowTaskNode.getRenWuJBXXBH());
		}
		if (flowTaskNode.getFtn_Status() != null) {
			hql += " and tFlowTaskNode.ftn_Status = ?";
			params.add(flowTaskNode.getFtn_Status());
		}
		if (flowTaskNode.getFlowTemplateNodeID() != null && !"".equals(flowTaskNode.getFlowTemplateNodeID())) {
			hql += " and tFlowTaskNode.flowTemplateNode.ftn_ID = ?";
			params.add(flowTaskNode.getFlowTemplateNodeID());
		}
		// System.out.println("user code          :"+flowTaskNode.getFtn_UserCode()+"    -----------"+flowTaskNode.getFtn_Status()+"---------------"+flowTaskNode.getSort());
		if (flowTaskNode.getFtn_UserCode() != null) {
			SessionInfo sessionInfo = (SessionInfo) ServletActionContext.getRequest().getSession().getAttribute(ResourceUtil.getSessionInfoName());
			//System.out.println(sessionInfo.getRoleIds() + "@@@" + sessionInfo.getRoleIds().indexOf(ResourceUtil.ADMIN_ROLE_ID));
			if (sessionInfo.getRoleIds().indexOf(ResourceUtil.ADMIN_ROLE_ID) < 0) {// 如果不是管理员
				hql += " and tFlowTaskNode.ftn_UserCode in ( ";
				String userCodes = flowTaskNode.getFtn_UserCode();
				System.out.println("+++添加前的userCodes:" + userCodes);
				userCodes = addWTRUserCodes(userCodes, new Date());
				System.out.println("+++添加后的userCodes:" + userCodes);
				boolean first = true;
				for (String userCode : userCodes.split(",")) {
					if (first) {
						hql += "?";
						params.add(userCode);
						first = false;
					} else {
						hql += ",?";
						params.add(userCode);
					}
				}
				hql += ") ";
			}
		}
		if (flowTaskNode.getFtn_Class() != null) {
			if (flowTaskNode.getFtn_Class().indexOf(",") > 0) {
				String[] classArr = flowTaskNode.getFtn_Class().split(",");
				hql += " and tFlowTaskNode.flowNodeClass.fnc_ID in(";
				int x = 0;
				for (String cla : classArr) {
					if (x > 0) {
						hql += ",";
					}
					hql += "?";
					params.add(cla);
					x++;
				}
				hql += ")";
			} else {
				hql += " and tFlowTaskNode.flowNodeClass.fnc_ID = ?";
				params.add(flowTaskNode.getFtn_Class());
			}
		}
		if (flowTaskNode.getDatetimeEnd() != null && !flowTaskNode.getDatetimeEnd().equals("")) {
			hql += " and tFlowTaskNode.ftn_HandleBeginTime <= ? ";

			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String dateStr = sdf.format(flowTaskNode.getDatetimeEnd()) + " 23:59";
			try {
				params.add(new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(dateStr));
			} catch (ParseException e) {
				e.printStackTrace();
			}

		}
		if (flowTaskNode.getDatetimeStart() != null && !flowTaskNode.getDatetimeStart().equals("")) {
			hql += " and tFlowTaskNode.ftn_HandleBeginTime >= ? ";
			params.add(flowTaskNode.getDatetimeStart());
		}
		if (flowTaskNode.getEnddatetimeEnd() != null && !flowTaskNode.getEnddatetimeEnd().equals("")) {
			hql += " and tFlowTaskNode.ftn_HandleEndTime <= ? ";
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String dateStr = sdf.format(flowTaskNode.getEnddatetimeEnd()) + " 23:59";
			try {
				params.add(new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(dateStr));
			} catch (ParseException e) {
				e.printStackTrace();
			}

		}
		if (flowTaskNode.getEnddatetimeStart() != null && !flowTaskNode.getEnddatetimeStart().equals("")) {
			hql += " and tFlowTaskNode.ftn_HandleEndTime >= ? ";
			params.add(flowTaskNode.getEnddatetimeStart());
		}

		if (flowTaskNode.getYeWuZLBH() != null && !"".equals(flowTaskNode.getYeWuZLBH())) {
			//System.out.println("flowTaskNode.getYeWuZLBH()======" + flowTaskNode.getYeWuZLBH());
			hql += "and (tFlowTaskNode.renWuJBXXBH in(select tr.bianHao from TRenWuJBXX tr where tr.yeWuZL.bianHao=?) " + "or tFlowTaskNode.xiangMuJBXXBH in(select tx.xiangMuBH from TXiangMuJBXX tx where tx.yeWuZLWH.bianHao=?) ) ";
			params.add(flowTaskNode.getYeWuZLBH());
			params.add(flowTaskNode.getYeWuZLBH());
		}
		if (flowTaskNode.getQiYeMC() != null && !"".equals(flowTaskNode.getQiYeMC())) {
			hql += "and (tFlowTaskNode.renWuJBXXBH in(select tr.bianHao from TRenWuJBXX tr where tr.qiYeMC like ?) " + "or tFlowTaskNode.xiangMuJBXXBH in(select tx.xiangMuBH from TXiangMuJBXX tx where tx.shouPingZT.qiYeZWMC like ? or tx.shouPingZT.qiYeYWMC like ?) ) ";
			params.add("%" + flowTaskNode.getQiYeMC() + "%");
			params.add("%" + flowTaskNode.getQiYeMC() + "%");
			params.add("%" + flowTaskNode.getQiYeMC() + "%");
		}
		
		if (renWuHQL != null && !"".equals(renWuHQL)) {
			hql += " and tFlowTaskNode.renWuJBXXBH in(" + renWuHQL + ")";
			if (renWuHQLParams != null && renWuHQLParams.size() != 0) {
				params.addAll(renWuHQLParams);
			}
		}
		if (xiangMuHQL != null && !"".equals(xiangMuHQL)) {
			hql += " and tFlowTaskNode.xiangMuJBXXBH in(" + xiangMuHQL + ")";
			if (xiangMuHQLParams != null && xiangMuHQLParams.size() != 0) {
				params.addAll(xiangMuHQLParams);
			}
		}
		if (flowTaskNode.getXiangMuMC() != null & !"".equals(flowTaskNode.getXiangMuMC())) {
			hql += " and tFlowTaskNode.xiangMuJBXXBH in (select tt.bianHao from TXiangMuJBXX tt where tt.xiangMuMC like ?) ";
			params.add("%" + flowTaskNode.getXiangMuMC() + "%");
		}
		if (flowTaskNode.getDatagridType() != null && flowTaskNode.getDatagridType().equals("xiangMuLCJK")) {
			hql += "  and tFlowTaskNode.ftn_ID in (select max(tt.ftn_ID) from TFlowTaskNode tt where tt.ftn_Status=1 group by tt.flow.flo_ID,tt.flowTemplateNode.ftn_ID) ";
		}
		if (flowTaskNode.getDatagridType() != null && flowTaskNode.getDatagridType().equals("renWuLCJK")) {
			hql += "  and tFlowTaskNode.ftn_ID in (select max(tt.ftn_ID) from TFlowTaskNode tt where tt.ftn_Status=1 group by tt.flow.flo_ID,tt.flowTemplateNode.ftn_ID) ";
			SessionInfo sessionInfo = (SessionInfo) ServletActionContext.getRequest().getSession().getAttribute(ResourceUtil.getSessionInfoName());
			if (!sessionInfo.isPassable("xianshiSYRWD")) {
				hql += " and (tFlowTaskNode.renWuJBXXBH in (select tr.bianHao from TRenWuJBXX tr where tr.yeWuCBR.userID=? ) or tFlowTaskNode.xiangMuJBXXBH in (select tx.xiangMuBH from TXiangMuJBXX tx where tx.renWuJBXX.yeWuCBR.userID=?)) ";
				params.add(sessionInfo.getUserId());
				params.add(sessionInfo.getUserId());
			}
		}
		if (flowTaskNode.getLiuChengJD() != null && !"".equals(flowTaskNode.getLiuChengJD()) && !"310".equals(flowTaskNode.getLiuChengJD())) {
			hql += " and tFlowTaskNode.ftn_Name_cn = ? ";
			params.add(flowTaskNode.getLiuChengJD());
		}
		if (flowTaskNode.getFtn_XiangMuJD() != null && flowTaskNode.getFtn_XiangMuJD() != 310) {
			hql += " and tFlowTaskNode.ftn_XiangMuJD = ? ";
			params.add(flowTaskNode.getFtn_XiangMuJD());
		}
		if (flowTaskNode.getFtn_State() != null && !"".equals(flowTaskNode.getFtn_State())) {
			hql += " and tFlowTaskNode.ftn_State = ? ";
			params.add(flowTaskNode.getFtn_State());
		}
		if (flowTaskNode.getXiangMuYCLX() != null && !"".equals(flowTaskNode.getXiangMuYCLX())) {
			hql += " and tFlowTaskNode.xiangMuYCLX like ?";
			params.add("%" + flowTaskNode.getXiangMuYCLX() + "%");
		}
		if (flowTaskNode.getFtn_Name_cn() != null && !"".equals(flowTaskNode.getFtn_Name_cn())) {
			hql += " and tFlowTaskNode.ftn_Name_cn=? ";
			params.add(flowTaskNode.getFtn_Name_cn());
		}
		if (flowTaskNode.getXiangMuZT() != null) {
			//System.out.println("flowTaskNode.getXiangMuZT()================" + flowTaskNode.getXiangMuZT());
			hql += " and (tFlowTaskNode.xiangMuJBXXBH is null or tFlowTaskNode.xiangMuJBXXBH in(select tx.bianHao from TXiangMuJBXX tx where tx.xiangMuZT=?)) ";
			params.add(flowTaskNode.getXiangMuZT());
		}
		return hql;
	}

	*//**
	 * 递归查询添加受托人的userCodes
	 * 
	 * @param userCodeList
	 * @param userCodes
	 * @return
	 *//*
	// userCodes至少有一个
	private String addWTRUserCodes(String userCodes, Date date) {
		
		 * for(String userCode : userCodes.split(",")) { List<TWeiTuoWH> weiTuoWHs = weiTuoWHDao.find("from TWeiTuoWH t where t.shouTuoR=? and ?>=t.kaiShiSJ and ?<=t.jieShuSJ ",new Object[]{userCode,date,date}); if(weiTuoWHs==null||weiTuoWHs.size()==0) { continue; }else { String currentUserCodes = ""; boolean first = true; for(TWeiTuoWH weiTuoWH : weiTuoWHs) { if(first) { currentUserCodes += weiTuoWH.getWeiTuoR(); first = false; }else { currentUserCodes += ","+weiTuoWH.getWeiTuoR(); } } userCodes += ","+addWTRUserCodes(currentUserCodes,date); } } return userCodes;
		 
		return null;
	}

	private String addOrder(FlowTaskNode flowTaskNode, String hql) {
		if (flowTaskNode.getSort() != null) {
			hql += " order by ";
			String[] sortArr = flowTaskNode.getSort().split(",");
			String[] orderArr = flowTaskNode.getOrder().split(",");
			for (int i = 0; i < sortArr.length; i++) {
				if (i > 0)
					hql += ",";
				hql += sortArr[i] + " " + orderArr[i];
			}
		}
		return hql;

	}

	public FlowTaskNode changeModel(TFlowTaskNode to) {
		FlowTaskNode o = new FlowTaskNode();
		BeanUtils.copyProperties(to, o);
		if (to.getFlow() != null) {
			o.setFlo_ID(to.getFlow().getFlo_ID());
		}
		if (to.getFlowNodeClass() != null) {
			o.setFtn_Class(to.getFlowNodeClass().getFnc_ID());
		}

		if (o.getFtn_HandleUserCode() == null || "".equals(o.getFtn_HandleUserCode())) {
			String userCodes = o.getFtn_UserCode();
			if (userCodes != null && !"".equals(userCodes)) {
				String[] userCodeArr = userCodes.split(",");
				String userName = "";
				int temp = 0;
				for (int i = 0; i < userCodeArr.length; i++) {
					TYongHu user = (TYongHu) flowTaskNodeDao.get(TYongHu.class, userCodeArr[i]);
					if (user != null) {
						if (temp > 0) {
							userName += ",";
						}
						userName += user.getXingMing();
					}
				}
				o.setFtn_HandleUserName(userName);
			}
		} else {
			TYongHu user = (TYongHu) flowTaskNodeDao.get(TYongHu.class, o.getFtn_HandleUserCode());
			if (user != null) {
				o.setFtn_HandleUserName(user.getXingMing());
			}
		}
		o.setFlowTemplateNodeID(to.getFlowTemplateNode().getFtn_ID());

		// 当前流程的所有处理人name(只拿前4个)

		String[] flnUserCode = null;
		if (to.getFtn_Assignee() != null) {
			flnUserCode = to.getFtn_Assignee().split(",");
		} else {
			flnUserCode = new String[] { to.getFtn_UserCode() };
		}

		StringBuffer sbuf = new StringBuffer();
		for (int i = 0; i < flnUserCode.length && i < 5; i++) {
			TYongHu tuser = (TYongHu) flowTaskNodeDao.get(TYongHu.class, flnUserCode[i]);
			if (tuser != null) {
				String userName = tuser.getXingMing();
				if (i == 0) {
					sbuf.append(userName);
				} else {
					sbuf.append("," + userName);
				}
			}
		}
		o.setLiuChengJDCLR(sbuf.toString());
		try {
			o.setFlowCreateTime(to.getFlow().getFlo_CreateTime());
		} catch (ObjectNotFoundException e) {
			e.printStackTrace();
		}
		if (o.getFtn_HandleUserName() != null && "".equals(o.getFtn_HandleUserName())) {
			o.setFtn_HandleUserName("未知用户");
		}
		return o;
	}

	public List<FlowTaskNode> changeModel(List<TFlowTaskNode> tFlowTaskNode) {
		List<FlowTaskNode> list = new ArrayList<FlowTaskNode>();
		for (TFlowTaskNode to : tFlowTaskNode) {
			FlowTaskNode o = new FlowTaskNode();
			BeanUtils.copyProperties(to, o);
			
			if (to.getFlow() != null) {
				o.setFlo_ID(to.getFlow().getFlo_ID());
			}
			if (to.getFlowNodeClass() != null) {
				o.setFtn_Class(to.getFlowNodeClass().getFnc_ID());
			}

			if (o.getFtn_HandleUserCode() == null || "".equals(o.getFtn_HandleUserCode())) {
				String userCodes = o.getFtn_UserCode();
				if (userCodes != null && !"".equals(userCodes)) {
					String[] userCodeArr = userCodes.split(",");
					String userName = "";
					int temp = 0;
					for (int i = 0; i < userCodeArr.length; i++) {
						TYongHu user = (TYongHu) flowTaskNodeDao.get(TYongHu.class, userCodeArr[i]);
						if (user != null) {
							if (temp > 0) {
								userName += ",";
							}
							userName += user.getXingMing();
						}
					}
					o.setFtn_HandleUserName(userName);
				}
			} else {
				TYongHu user = (TYongHu) flowTaskNodeDao.get(TYongHu.class, o.getFtn_HandleUserCode());
				if (user != null) {
					o.setFtn_HandleUserName(user.getXingMing());
				}
			}

			// 项目/任务相关r信息
			if (to.getXiangMuJBXXBH() != null && !"".equals(to.getXiangMuJBXXBH())) {
				logger.info("xiangmubh:" + to.getXiangMuJBXXBH());
				XiangMuJBXX x = xiangMuJBXXService.get(to.getXiangMuJBXXBH());
				if (x != null) {
					o.setQiYeMC(x.getQiYeZWMC());
					o.setXiangMuMC(x.getXiangMuMC());
					o.setXiangMuBH(x.getBianHao());
					o.setYeWuZLBH(x.getYeWuZLBH());
					o.setYeWuZLMC(x.getYeWuZLMC());
					o.setChuShiPJRQXS(x.getFaQiRQStr());
					o.setPingJiJZRXS(x.getPingJiJZRStr());
				}
			}

			// 当前流程的所有处理人name(只拿前4个)

			String[] flnUserCode = null;
			if (to.getFtn_Assignee() != null) {
				flnUserCode = to.getFtn_Assignee().split(",");
			} else {
				flnUserCode = new String[] { to.getFtn_UserCode() };
			}

			StringBuffer sbuf = new StringBuffer();
			for (int i = 0; i < flnUserCode.length && i < 5; i++) {
				TYongHu tuser = (TYongHu) flowTaskNodeDao.get(TYongHu.class, flnUserCode[i]);
				if (tuser != null) {
					String userName = tuser.getXingMing();
					if (i == 0) {
						sbuf.append(userName);
					} else {
						sbuf.append("," + userName);
					}
				}
			}
			o.setLiuChengJDCLR(sbuf.toString());
			try {
				o.setFlowCreateTime(to.getFlow().getFlo_CreateTime());
			} catch (ObjectNotFoundException e) {
				e.printStackTrace();
			}
			if (o.getFtn_HandleUserName() != null && "".equals(o.getFtn_HandleUserName())) {
				o.setFtn_HandleUserName("未知用户");
			}
			list.add(o);
		}
		// System.out.println("list.size()=========================" + list.size());
		return list;
	}

	public List<FlowTaskNode> changeModel_His(List<TFlowTaskNode> tFlowTaskNode) {
		
		 * List<FlowTaskNode> list = new ArrayList<FlowTaskNode>(); for(TFlowTaskNode_His to:tFlowTaskNode){ FlowTaskNode o = new FlowTaskNode(); BeanUtils.copyProperties(to, o); if(to.getFlow()!=null){ o.setFlo_ID(to.getFlow().getFlo_ID()); } if(to.getFlowNodeClass()!=null){ o.setFtn_Class(to.getFlowNodeClass().getFnc_ID()); } if(o.getFtn_HandleUserCode()==null||"".equals(o.getFtn_HandleUserCode())){ String userCodes = o.getFtn_UserCode(); if(userCodes!=null&&!"".equals(userCodes)){ String[] userCodeArr = userCodes.split(","); String userName_cn = ""; String userName_en = ""; int temp = 0; for(int i=0;i<userCodeArr.length;i++){ TUser user = (TUser) flowTaskNodeDao.get(TUser.class,userCodeArr[i]); if(user!=null){ if(temp>0){ userName_cn+=","; userName_en+=","; } userName_cn +=user.getUserName_cn(); userName_en +=user.getUserName_en(); } } o.setFtn_HandleUserName_cn(userName_cn); o.setFtn_HandleUserName_en(userName_en); } }else{ TUser user = (TUser) flowTaskNodeDao.get(TUser.class, o.getFtn_HandleUserCode()); if(user!=null){ o.setFtn_HandleUserName_cn(user.getUserName_cn()); o.setFtn_HandleUserName_en(user.getUserName_en()); } } //项目/任务相关r信息 if (to.getXiangMuJBXXBH() != null && !"".equals(to.getXiangMuJBXXBH())) { XiangMuJBXX x = xiangMuJBXXService.get(to.getXiangMuJBXXBH()); o.setQiYeMC(x.getShouPingZTMC()); o.setXiangMuMC(x.getXiangMuMC()); o.setXiangMuBH(x.getXiangMuBH()); o.setYeWuZLBH(x.getYeWuZLBH()); o.setYeWuZLMC(x.getYeWuZLMC()); o.setZuZhiJGMC(x.getZuZhiJGMC()); }else { RenWuJBXX renWuJBXX = renWuJBXXService.get(to.getRenWuJBXXBH()); if(renWuJBXX!=null) { o.setQiYeMC(renWuJBXX.getQiYeMC()); o.setYeWuZLBH(renWuJBXX.getYeWuZLBH()); o.setYeWuZLMC(renWuJBXX.getYeWuZLMC()); } }
		 * 
		 * 当前流程的所有处理人name(只拿前4个)
		 * 
		 * String[] flnUserCode = to.getFlowNode().getFln_UserCode().split(","); StringBuffer sbuf = new StringBuffer(); for(int i = 0;i<flnUserCode.length&&i<5;i++) { TUser tuser = (TUser)userDao.get(TUser.class, flnUserCode[i]); String userName = Locale.CHINA.equals(Locales.getLocale())?tuser.getUserName_cn():tuser.getUserName_en(); if(i == 0) { sbuf.append(userName); }else { sbuf.append(","+userName); } } o.setFln_ID(to.getFlowNode().getFln_ID()); o.setLiuChengJDCLR(sbuf.toString()); try{ o.setFlowCreateTime(to.getFlow().getFlo_CreateTime()); }catch(ObjectNotFoundException e) { e.printStackTrace(); }
		 * 
		 * 
		 * if(o.getFtn_HandleUserName_cn()!=null&&"".equals(o.getFtn_HandleUserName_cn())){ o.setFtn_HandleUserName_cn("未知用户"); o.setFtn_HandleUserName_en("未知用户"); } list.add(o); }
		 * 
		 * 
		 * return list;
		 
		return null;
	}

	*//**
	 * 根据项目阶段查询该阶段下所有的流程节点下拉列表的数据
	 *//*
	@Override
	public List<DictionaryDetail> liuChengJDSelectData(FlowTaskNode flowTaskNode) {
		
		 * String hql = "select t from TFlowTaskNode t where t.ftn_ID in(select max(tt.ftn_ID) from TFlowTaskNode tt where tt.ftn_XiangMuJD=? group by ftn_Name_cn)"; List params = new ArrayList(); params.add(flowTaskNode.getFtn_XiangMuJD()); List<TFlowTaskNode> infos = flowTaskNodeDao.find(hql, params); List ddList = new ArrayList<DictionaryDetail> (); DictionaryDetail d = new DictionaryDetail(); d.setDetailID("310"); d.setDetailName_cn("——请选择——"); d.setOrderNO(0); ddList.add(d); for(TFlowTaskNode ftn : infos) { DictionaryDetail dd = new DictionaryDetail(); dd.setDetailID(ftn.getFtn_Name_cn()); dd.setDetailName_cn(ftn.getFtn_Name_cn()); dd.setOrderNO(ftn.getFtn_Index()); ddList.add(dd); } Collections.sort(ddList, new DictionaryDetailComparator()); return ddList;
		 
		return null;
	}

	*//**
	 * 催办
	 *//*
	@Override
	public void cuiBan(FlowTaskNode flowTaskNode) {

		
		 * String[] ftnids = flowTaskNode.getFtnids().split("-"); String[] qiYeMCs = flowTaskNode.getQiYeMCs().split("-"); //String[] buZhouNames = flowTaskNode.getBuZhouNames().split("-"); String cuiBanRId = flowTaskNode.getCuiBanRId();
		 * 
		 * TUser user = (TUser)userDao.get(TUser.class, cuiBanRId); String cuiBanRName = Locale.CHINA.equals(Locales.getLocale())?user.getUserName_cn():user.getUserName_en(); for(int i=0;i<ftnids.length;i++) { TFlowTaskNode ftn = (TFlowTaskNode)flowTaskNodeDao.get(TFlowTaskNode.class,ftnids[i]); String qiYeMC = qiYeMCs[i]; int fncid = Integer.parseInt(ftn.getFlowNodeClass().getFnc_ID()); if(ftn.getFlowNodeClass()!=null&&fncid>=100&&fncid<200) { //如果100-200的是上会评审需要去催对应的评级秘书 String hql = "from TFlowTaskNode_His t where  t.xiangMuJBXXBH=? and t.ftn_Status=2 and t.flowNodeClass.fnc_ID='9' order by t.ftn_HandleEndTime desc"; //这套流程模板中最近的一次上会设定 TFlowTaskNode_His ftn2 = (TFlowTaskNode_His)(flowTaskNodeDao.find(hql, new Object[]{ftn.getXiangMuJBXXBH()})).get(0); xiTongXXDao.sendMsg(cuiBanRId, ftn2.getFtn_HandleUserCode(),cuiBanRName+"提示您：【"+qiYeMCs[i]+"】的上会评审请尽快处理！", TXiTongXX.CUIBAN,TXiTongXX.WEITANCHUANG); }else{ for(String assignee : ftn.getFtn_Assignee().split(",")) { FlowTaskNode flowTaskNode3 = new FlowTaskNode(); flowTaskNode3.setXiangMuJBXXBH(ftn.getXiangMuJBXXBH()); flowTaskNode3.setFtn_UserCode(assignee); flowTaskNode3.setFtn_Class(ftn.getFlowNodeClass().getFnc_ID()); flowTaskNode3.setRenWuJBXXBH(ftn.getRenWuJBXXBH()); List<TFlowTaskNode> ftns = flowTaskNodeDao.find(flowTaskNode3, null, null, null, null); if(ftns!=null&&ftns.size()>0) { if(doPath(ftns.get(0)).equals("")) { xiTongXXDao.sendMsg(cuiBanRId,ftns.get(0).getFtn_UserCode(),cuiBanRName+"提示您：【"+qiYeMC+"】的"+"【"+ftns.get(0).getFtn_Name_cn() +"】请尽快处理!",TXiTongXX.CUIBAN,TXiTongXX.WEITANCHUANG); }else { xiTongXXDao.sendMsg(cuiBanRId,ftns.get(0).getFtn_UserCode(),"<a href='javascript:void(0);' style='color:#3873B8;' onclick=\""+doPath(ftns.get(0))+"\" >"+cuiBanRName+"提示您：【"+qiYeMC+"】的"+"【"+ftns.get(0).getFtn_Name_cn() +"】请尽快处理！</a>",TXiTongXX.CUIBAN,TXiTongXX.WEITANCHUANG); } } } } }
		 
	}

	*//**
	 * 根据ftn，选择对应的处理方式
	 * 
	 * @param ftn
	 * @return
	 *//*
	private String doPath(TFlowTaskNode ftn) {
		Map param = new HashMap();
		param.put("ftn_ID", ftn.getFtn_ID());
		param.put("flag", "2");
		param.put("xiangMuBH", ftn.getXiangMuJBXXBH());
		param.put("renWuJBXXBH", ftn.getRenWuJBXXBH());
		// param.put("yeWuZLBH",ftn.getXiangMuJBXXBH());
		String url;
		if (ftn.getFtn_FormUrl().startsWith("#addTab")) { // 如果需要新增一个标签页的方式处理，请将formurl设置为#addTab,\sdfsdf.action的格式
			url = ftn.getFtn_FormUrl().substring(ftn.getFtn_FormUrl().indexOf(",") + 1);
		} else {
			url = UrlUtil.addParams(ftn.getFtn_FormUrl(), param);
		}
		String dopath = "";
		if (ftn.getFtn_FormUrl() != null && !"".equals(ftn.getFtn_FormUrl())) {
			if (ftn.getFtn_FormUrl().startsWith("#addTab")) { // 添加标签页的处理方式
				dopath = "addatab$('" + ftn.getFtn_Name_cn() + "','" + url + "','" + ftn.getFtn_ID() + "')";
			} else if (ftn.getFtn_Name_cn().equals("上会评审") || ftn.getFtn_Name_cn().equals("上会评审意见汇总") || ftn.getFtn_Name_cn().equals("评级结果确认")) {
				dopath = "viewHBCN$('" + url + "','" + ftn.getFtn_ID() + "')";
			} else {
				dopath = "view$('" + url + "','" + ftn.getFtn_ID() + "')";
			}
		} else if (ftn.getFlowNodeClass().getFnc_ID().startsWith("-")) { // 查看项目的处理方式
			dopath = "viewXM$('" + ftn.getXiangMuJBXXBH() + "','" + ftn.getFtn_ID() + "')";
		}
		return dopath;
	}

	*//**
	 * 根据项目编号,查询当前项目处于哪个步骤
	 *//*
	@Override
	public String findBuZhouMC(String xiangMuBH) {
		String hql = "from TFlowTaskNode t where t.xiangMuJBXXBH=? and t.ftn_Status=1 ";
		List<TFlowTaskNode> list = flowTaskNodeDao.find(hql, new Object[] { xiangMuBH });
		String name;

		if (list.size() <= 0) {
			name = "终止";
		} else {
			TFlowTaskNode ftn = list.get(0);
			int fncid = Integer.parseInt(ftn.getFlowNodeClass().getFnc_ID());
			if (fncid >= 100 && fncid < 200) {
				name = "上会评审";
			} else {
				name = ftn.getFtn_Name_cn();
			}
		}
		return name;
	}

	@Override
	public boolean checkFtn(FlowTaskNode flowTaskNode) {
		if (flowTaskNodeDao.get("from TFlowTaskNode t where t.ftn_ID=? and t.ftn_Status=1 ", new Object[] { flowTaskNode.getFtn_ID() }) != null) {
			return true;
		}
		return false;
	}

	@Override
	public boolean updateUser(String ftn_ID, String userID) {
		Object o = flowTaskNodeDao.get(TFlowTaskNode.class, ftn_ID);

		if (o != null) {
			TFlowTaskNode t = (TFlowTaskNode) o;
			List<TFlowTaskNode> list = flowTaskNodeDao.find("from TFlowTaskNode t where t.flow = ? and t.flowTemplateNode = ?", new Object[] { t.getFlow(), t.getFlowTemplateNode() });
			String ass;
			if (t.getFtn_Assignee() != null) {
				ass = t.getFtn_Assignee().replace(t.getFtn_UserCode(), userID);
			} else {
				ass = userID;
			}
			for (TFlowTaskNode tFlowTaskNode : list) {
				if (t.getFtn_ID().equals(tFlowTaskNode.getFtn_ID())) {
					tFlowTaskNode.setFtn_UserCode(userID);
					tFlowTaskNode.setFtn_Assignee(ass);
					flowTaskNodeDao.update(tFlowTaskNode);
				} else {
					tFlowTaskNode.setFtn_Assignee(ass);
					flowTaskNodeDao.update(tFlowTaskNode);
				}
			}

			return true;
		}
		return false;
	}

	@Override
	public void editXiangMuYCLX(FlowTaskNode flowTaskNode) {
		
		 * for (String id : flowTaskNode.getIds().split(",")) { TFlowTaskNode_His t = (TFlowTaskNode_His)flowTaskNodeDao.get(TFlowTaskNode_His.class, id); if (t != null) { t.setXiangMuYCLX(flowTaskNode.getEditVersion()); flowTaskNodeDao.update(t); } }
		 
	}

}
*/